package com.amumu.drama.common.constant;

import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

/**
 * @author sunzhuang
 * @date 2024/5/14 13:56
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc 发货状态
 */
@Getter
public enum DeliveryStatusEnum {
    /**
     * 支付状态
     */
    WAIT_DELIVERY(0, "待发货"),
    DELIVERY(1, "发货中"),
    SUCCESS(2, "发货成功"),
    FAIL(3, "发货失败"),
    REFUND(4, "已退货");

    private Integer code;

    private String desc;

    DeliveryStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, DeliveryStatusEnum> UNINDEX = Maps.uniqueIndex(Arrays.asList(values()), DeliveryStatusEnum::getCode);

    public static DeliveryStatusEnum getByCode(Integer code) {
        return UNINDEX.get(code);
    }

    public static boolean idDelivery(Integer code) {
        return DELIVERY.getCode().equals(code);
    }

    public static boolean isWaitDelivery(Integer deliveryStatus) {
        return WAIT_DELIVERY.getCode().equals(deliveryStatus);
    }
}
